home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-15 | 8.6 KB | 364 lines | [TEXT/KAHL] |
- /*
- * ShapeAction.c
- *
- * Robert Dierkes, April 26, 1993
- *
- * Change History:
- *
- * 4/93 ??? New
- * 4/96 bob Updated #includes to support changed GX Library names.
- * Added the copyright info.
- *
- *
- * © Apple Computer, Inc. 1990 - 1996 All rights reserved
- *
- */
-
-
- #undef MAC_HEADERS
-
-
- /*------------------*/
- /* Include Files */
- /*------------------*/
- #ifndef MAC_HEADERS
- #include <Dialogs.h>
- #include <Controls.h>
- #endif MAC_HEADERS
-
- #define debugging /* for gxGraphicNotices */
-
- #include <GXGraphics.h>
- #include "GraphicsLibraries.h"
- #include "QDLibrary.h" /* ShortRectToFixed for DrawGrayBox */
-
- #include "ResourceIDs.h"
- #include "ShapeAction.h"
- #include "ShapeSetup.h"
-
-
- /*----------------------*/
- /* Global Declarations */
- /*----------------------*/
-
-
- /*------------------------------*/
- /* External Declarations */
- /*------------------------------*/
- extern GlobalStructure globals;
-
-
- /*------------------------------*/
- /* Local ProtoTypes */
- /*------------------------------*/
- void ShowLocalBounds (gxShape *p1stShape, long shapeCount);
- void HighlightShapePartBoxes (ControlHandle *ph1stControl, gxShapePart partsHit);
- long GetShapeBoxIndexFromPoint (gxShape boxes, gxPoint *pWhere);
- void UpdateShapeName (gxShape theShape, gxShapeType *pLastType);
- pascal void DrawGrayBox (WindowPtr pWindow, short itemNum);
-
-
- void
- ShowLocalBounds (gxShape *p1stShape, long shapeCount)
- {
- register
- gxShape *pShape,
- rectShape;
- gxRectangle bounds;
-
- pShape = p1stShape + shapeCount - 1;
-
- rectShape = GXNewShape (gxRectangleType);
- GXSetShapeFill (rectShape, gxClosedFrameFill);
- SetShapeCommonColor (rectShape, gxGray);
-
- while (shapeCount--)
- {
- GXGetShapeLocalBounds (*pShape--, &bounds);
- GXSetRectangle (rectShape, &bounds);
- GXDrawShape (rectShape);
- }
-
- GXDisposeShape (rectShape);
- }
-
-
- void
- ShowControlPoints (gxShape *p1stShape, long shapeCount)
- {
- register
- gxShape *pShape;
- long contourCount,
- pointCount;
- gxPoint pt;
- gxShape pointShape;
- gxRectangle bounds;
-
- pShape = p1stShape + shapeCount - 1;
- pointShape = GXNewShape (gxRectangleType);
-
- while (shapeCount--)
- {
- /* gxGlyphType has too many control points so skip it */
- if (GXGetShapeType (*pShape) != gxGlyphType)
- {
- contourCount = GXCountShapeContours (*pShape);
- while (contourCount--)
- {
- pointCount = GXGetShapePoints (*pShape, 1, gxSelectToEnd, nil);
- while (pointCount)
- {
- /// GetShapeIndexPoint (*pShape, pointCount--, &pt);
- GXGetShapePoints (*pShape, pointCount--, 1, &pt);
- bounds.left = pt.x - fixed1;
- bounds.top = pt.y - fixed1;
- bounds.right = pt.x + fixed1;
- bounds.bottom = pt.y + fixed1;
- GXSetRectangle (pointShape, &bounds);
- GXDrawShape (pointShape);
- }
- }
- }
- pShape--;
- }
-
- GXDisposeShape (pointShape);
- }
-
-
- /*
- *
- */
- void
- HighlightShapePartBoxes (ControlHandle *ph1stControl, gxShapePart partsHit)
- {
- #define controlCount 11
-
- ControlHandle *pControl;
- gxRectangle controlRect;
- gxShape highlight;
- static
- gxShapePart lastPartsHit = gxAnyPart;
- gxShapePart partMask;
-
- if (partsHit == lastPartsHit)
- return;
-
- highlight = GXNewShape (gxRectangleType);
- GXSetShapeFill (highlight, gxClosedFrameFill);
- GXIgnoreGraphicsNotice (color_already_set);
-
- partMask = gxPatternPart;
- for (pControl = ph1stControl + controlCount; --pControl >= ph1stControl; partMask >>= 1)
- {
- /* Compare single bit of current shapeParts against previous shapeParts */
- if ((partsHit & partMask) != (lastPartsHit & partMask))
- {
- (void) ShortRectToFixed (&(**pControl)->contrlRect, &controlRect);
- controlRect.left -= fixed1;
- controlRect.top -= fixed1;
- controlRect.right += fixed1;
-
- GXSetRectangle (highlight, &controlRect);
- SetShapeCommonColor (highlight, (partsHit & partMask) ? red : gxWhite);
- GXDrawShape (highlight);
- }
- }
- lastPartsHit = partsHit;
-
- GXPopGraphicsNotice ();
- GXDisposeShape (highlight);
- }
-
-
- pascal void
- DrawGrayBox (WindowPtr pWindow, short itemNum)
- {
- GrafPtr savedPort;
- Rect shortBounds;
- gxRectangle bounds;
- gxShape boxShape;
- short itemType;
- Handle itemHandle;
-
- GetPort (&savedPort);
- SetPort (pWindow);
-
- GetDItem (pWindow, itemNum, &itemType, &itemHandle, &shortBounds);
- ShortRectToFixed (&shortBounds, &bounds);
- boxShape = GXNewRectangle (&bounds);
- GXSetShapeFill (boxShape, gxClosedFrameFill);
- GXSetShapePen (boxShape, 4 * fixed1);
- SetShapeCommonColor (boxShape, grayish + silver);
- GXDrawShape (boxShape);
- GXDisposeShape (boxShape);
-
- SetPort (savedPort);
-
- }
-
-
- void
- UpdateHitTestWindow (WindowPtr pWindow)
- {
- register
- gxShape *pShape;
- long shapeCount,
- shapeCountDown;
-
- UpdtDialog (pWindow, pWindow->visRgn);
-
- DrawGrayBox (pWindow, userGrayShapeNameBox);
- DrawGrayBox (pWindow, userGrayShapePartsBox);
- HighlightShapePartBoxes (&globals.hBounds, globals.partsHit);
-
- shapeCount = shapeCountDown = GXCountShapeContours (globals.boxes);
-
- /* Draw the background boxes */
- GXDrawShape (globals.boxes);
-
- if (globals.showLocalBounds)
- ShowLocalBounds (globals.pShapes, shapeCount);
-
- /* Draw all the hit testing shapes */
- pShape = globals.pShapes;
- while (shapeCountDown--)
- GXDrawShape (*pShape++);
-
- if (globals.showControlPoints)
- ShowControlPoints (globals.pShapes, shapeCount);
- }
-
-
- long
- GetShapeBoxIndexFromPoint (gxShape boxes, gxPoint *pWhere)
- {
- gxRectangle bounds;
- long index;
-
- index = GXCountShapeContours (boxes);
- while (index)
- {
- GXGetShapeBounds (boxes, index, &bounds);
- if (GXTouchesRectanglePoint (&bounds, pWhere))
- return (index - 1);
- index--;
- }
- return (notOnAnyShape);
- }
-
-
- void
- UpdateShapeName (gxShape theShape, gxShapeType *pLastType)
- {
- gxShapeType newType;
- Handle itemHandle;
- Str255 shapeNames[] = {"\pPoint",
- "\pLine",
- "\pCurve",
- "\pRectangle",
- "\pPolygon",
- "\pPath",
- "\pBitmap",
- "\pText",
- "\pGlyph",
- "\p"
- };
- StringPtr pShapeName;
- short itemType;
- Rect itemRect;
-
- if (theShape == nil)
- newType = gxEmptyType;
- else if ((newType = GXGetShapeType (theShape)) == *pLastType)
- return;
-
- *pLastType = newType;
-
- switch (newType)
- {
- case gxPointType: pShapeName = shapeNames [0]; break;
- case gxLineType: pShapeName = shapeNames [1]; break;
- case gxCurveType: pShapeName = shapeNames [2]; break;
- case gxRectangleType: pShapeName = shapeNames [3]; break;
- case gxPolygonType: pShapeName = shapeNames [4]; break;
- case gxPathType: pShapeName = shapeNames [5]; break;
- case gxBitmapType: pShapeName = shapeNames [6]; break;
- case gxTextType: pShapeName = shapeNames [7]; break;
- case gxGlyphType: pShapeName = shapeNames [8]; break;
- default: pShapeName = shapeNames [9]; break;
- }
-
- GetDItem (qd.thePort, staticShapeName, &itemType, &itemHandle, &itemRect);
- SetIText (itemHandle, pShapeName);
- }
-
-
- /*
- Draws a red rectangle around check box if the given point hit that type of gxShape part.
- */
- void
- UpdateShapePartInfo (Point *pQDWhere, GlobalStructure *pG)
- {
- gxPoint where;
- gxHitTestInfo hitInfo;
- long boxIndex;
- static
- gxShapeType lastType = gxEmptyType;
- gxShape shapeHit;
-
- ShortPointToFixed (pQDWhere, &where);
- boxIndex = GetShapeBoxIndexFromPoint (pG->boxes, &where);
-
- /* Change checkbox titles if point is in glyph gxShape */
- if (boxIndex == kWordGlyphs && lastType != gxGlyphType)
- {
- Point joinSize = {16, 106},
- startCapSize = {16, 90},
- endCapSize = {16, 88},
- dashSize = {16, 100};
-
- SizeControl (pG->hJoin, joinSize.h, joinSize.v);
- SizeControl (pG->hStartCap, startCapSize.h, startCapSize.v);
- SizeControl (pG->hEndCap, endCapSize.h, endCapSize.v);
- SizeControl (pG->hDash, dashSize.h, dashSize.v);
- SetCTitle (pG->hJoin, "\pGlyph Bounds");
- SetCTitle (pG->hStartCap, "\pGlyph First");
- SetCTitle (pG->hEndCap, "\pGlyph Last");
- SetCTitle (pG->hDash, "\pSide Bearing");
- }
- else if (boxIndex != kWordGlyphs && lastType == gxGlyphType)
- {
- Point joinSize = {16, 48},
- startCapSize = {16, 82},
- endCapSize = {16, 72},
- dashSize = {16, 52};
- Rect invalid = {274, 528, 354, 588};
-
- InvalRect (&invalid);
- SizeControl (pG->hJoin, joinSize.h, joinSize.v);
- SizeControl (pG->hStartCap, startCapSize.h, startCapSize.v);
- SizeControl (pG->hEndCap, endCapSize.h, endCapSize.v);
- SizeControl (pG->hDash, dashSize.h, dashSize.v);
- SetCTitle (pG->hJoin, "\pJoin");
- SetCTitle (pG->hStartCap, "\pStart Cap");
- SetCTitle (pG->hEndCap, "\pEnd Cap");
- SetCTitle (pG->hDash, "\pDash");
- }
-
- if (boxIndex == notOnAnyShape)
- {
- shapeHit = nil;
- hitInfo.what = gxNoPart;
- }
- else
- {
- shapeHit = pG->pShapes [boxIndex];
- GXHitTestShape (pG->pShapes [boxIndex], &where, &hitInfo);
- }
-
- UpdateShapeName (shapeHit, &lastType);
- HighlightShapePartBoxes (&pG->hBounds, hitInfo.what);
- pG->partsHit = hitInfo.what;
- }
-